package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.shop.AgentChannelBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.AgentChannelVo;
import com.ddwl.shop.service.AgentChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2021/7/22 10:22
 */
@Api(tags = "代理渠道")
@RequestMapping("/agentChannel")
@RestController
public class AgentChannelController extends BaseController {


    @Resource
    private AgentChannelService agentChannelService;


    @ApiOperation("新增代理渠道")
    @PostMapping()
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<String> save(@Valid @RequestBody AgentChannelBo bo) {
        return RestVo.ok(agentChannelService.save(bo));
    }

    @ApiOperation("修改代理渠道")
    @PutMapping()
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo update(@Valid @RequestBody AgentChannelBo bo) {
        agentChannelService.update(bo);
        return RestVo.ok();
    }

    @ApiOperation("获取代理渠道详情")
    @GetMapping()
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<AgentChannelVo> get(@RequestParam String id) {
        return RestVo.ok(agentChannelService.get(id));
    }

    @ApiOperation("删除代理渠道")
    @DeleteMapping()
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo delete(@RequestParam String id) {
        agentChannelService.delete(id);
        return RestVo.ok();
    }

    @ApiOperation("获取全部代理渠道")
    @GetMapping("/all")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<List<AgentChannelVo>> all() {
        return RestVo.ok(agentChannelService.all());
    }

}
